package com.his.util.util;

import java.time.LocalDateTime;
import java.util.Date;

public class StringUtil {
    public static Integer getId(String prefix, String str) {
        return Integer.parseInt(str.substring(prefix.length()));
    }

    /**
     * 设置首字母大写
     * @param str
     * @return
     */
    public static String uppercase(String str) {
        char[] arr = str.toCharArray();
        arr[0] = Character.toUpperCase(arr[0]);
        return new String(arr);
    }

    public static boolean stringMatch(String motherString, String modeString) {
        if (modeString.length() > motherString.length()) {
            return false;
        }

        char[] motherChars = motherString.toCharArray();
        char[] modeChars = modeString.toCharArray();

        for (char c : motherChars) {
            for (char c1 : modeChars) {
                if (c == c1) {
                    return true;
                }
            }
        }

        return false;
    }

    public static String getCurrentYearMonthDay() {
        LocalDateTime localDateTime = LocalDateTime.now();

        return localDateTime.getYear() + "-" + localDateTime.getMonthValue() + "-" + localDateTime.getDayOfMonth();
    }

    public static String calculateDate(String year, String month) {
        int tempMonth = Integer.parseInt(month) + 1;
        int tempYear = Integer.parseInt(year);

        tempYear += tempMonth % 12;
        tempMonth = tempMonth % 13 + tempMonth / 13;

        if (tempMonth < 10) {
            return tempYear + "-" + "0" + tempMonth;
        }

        return tempYear + "-" + tempMonth;
    }
}
